package org.smr.ministore.micro.client;

import org.blade.utils.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smr.ministore.entities.Goods;
import org.smr.ministore.entities.GoodsOrgan;
import org.smr.ministore.entities.vo.Assign2OrganVO;
import org.smr.ministore.entities.vo.Assign2OrgansVO;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import feign.hystrix.FallbackFactory;


@Component
public class HystrixGoodsClientFactory implements FallbackFactory<FeignGoodsMicroServiceClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(HystrixGoodsClientFactory.class);

    @Override
    public FeignGoodsMicroServiceClient create(Throwable cause) {
    HystrixGoodsClientFactory.LOGGER.info("fallback; reason was: {}", cause.getMessage());

        return new FeignGoodsMicroServiceClient() {

            @Override
            public int batchSave(List<Goods> entities) {
                return -1;
                }

            @Override
            public int batchModify(List<Goods> entities) {
                return -1;
                }

            @Override
            public int save(Goods entity) {
            return -1;
            }

            @Override
            public int updateById(Goods id) {
            return -1;
            }

            @Override
            public Goods queryById(Long id) {

                return getFuseGoods();
            }

            @Override
            public int deleteById(Long id) {
            return -1;
            }

            @Override
            public Pager<Goods> paginate(Goods entity, Long pageSize, Long pageNum) {
                LOGGER.error("{} 分页查询融断", entity);
                Pager<Goods> pager = new Pager<Goods>();
                pager.setPageSize(-1L);
                pager.setTotalCount(-1L);
                pager.setCurrentPage(-1L);
                return pager;
            }

            @Override
            public Goods selectByPrimaryKey(Goods entity) {
                return getFuseGoods();
            }

            @Override
            public int deleteByIdLogical(Long id) {
                return -1;
            }

            @Override
            public int assign(Assign2OrgansVO assignee) {
                return -1;
            }

            @Override
            public int assign(Assign2OrganVO goodsAssign2Organ) {
                return -1;
            }

            @Override
            public List<GoodsOrgan> queryGoodsAssignee(Assign2OrgansVO assignee) {
                return null;
            }

            private Goods getFuseGoods(){
                Goods goods = new Goods();
                goods.setId(-1L);
                return goods;
            }

        };//Return end
    }
}